package com.company.OfferGuide;

public class 构建乘积数组 {

    public static void main(String[] args) {
        int[] ints = constructArr(new int[]{1, 2, 3, 4, 5});
        for (int anInt : ints) {
            System.out.println(anInt);
        }
    }

    public static int[] constructArr(int[] a) {
        int left = 1;
        int right = 1;
        int[] ans = new int[a.length];
        for(int i=0;i<a.length;i++){
            ans[i] = left;
            left *= a[i];
        }
        for(int i=a.length-1;i>=0;i--){
            ans[i] *= right;
            right *= a[i];
        }
        return ans;
    }

}
